//
//  oldPersonalInfoViewController.m
//  laonianbangSupport
//
//  Created by 勇拓 李 on 18/3/5.
//  Copyright © 2018年 zaiyou. All rights reserved.
//

#import "oldPersonalInfoViewController.h"
#import "oldPersonIntroduceTableViewCell.h"
#import "oldEditInfoViewController.h"

@interface oldPersonalInfoViewController ()

@end

static NSString *const identifier = @"oldPersonIntroduceTableViewCell";

@implementation oldPersonalInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initView];
    [self initData];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)setText:(NSString *)text
{
    _text = text;
    [self.tableView reloadData];
}

#pragma mark - initView
- (void)initView
{
    self.navigationItem.title = @"个人资料";
    [self rigisterCell:identifier];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
}

#pragma mark - initData
- (void)initData
{
    if([ROLE  isEqual: agedCareOld])
    {
        _text = ACCOUNT_SINGLETON.accountInfo.addtion.ps;
    }
    else
    {
        _text = ACCOUNT_SINGLETON.accountInfo.addtion.introduce;
    }
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 4;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return [self configNormalCell:tableView indexPath:indexPath];
    
//    if (indexPath.row < 4) {
//        return [self configNormalCell:tableView indexPath:indexPath];
//    }
    
//    return [self configIntroduceCell:tableView indexPath:indexPath];
}


- (UITableViewCell *)configNormalCell:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil];
    cell.textLabel.font = [UIFont systemFontOfSize:15];
    cell.detailTextLabel.font = [UIFont systemFontOfSize:15];
    cell.textLabel.textColor = OLD_BLACK;
    cell.detailTextLabel.textColor = OLD_BLACK;
    
    switch (indexPath.row) {
        case 0:
            cell.textLabel.text = @"姓名";
            cell.detailTextLabel.text = ACCOUNT_SINGLETON.accountInfo.uname;
            break;
        case 1:
            cell.textLabel.text = @"性别";
            cell.detailTextLabel.text = [ACCOUNT_SINGLETON.accountInfo getAccountSex];
            break;
        case 2:
            cell.textLabel.text = @"年龄";
            cell.detailTextLabel.text = [ACCOUNT_SINGLETON.accountInfo getNStringOfAge];
            break;
        case 3:
            cell.textLabel.text = @"手机号码";
            cell.detailTextLabel.text = ACCOUNT_SINGLETON.accountInfo.mobile;
            break;
        default:
            break;
    }
    
    return cell;
    
}


- (UITableViewCell *)configIntroduceCell:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath
{
    oldPersonIntroduceTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath];
    
    if (cell == nil) {
        cell = [[oldPersonIntroduceTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    
    if (_text) {
        cell.label_text.text = _text;
    }
    else
    {
        cell.label_text.text = @"点击编辑信息";
    }
    
    return cell;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row < 4) {
        return 50;
    }
    
    return 146.f;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if (indexPath.row == 4) {
        oldEditInfoViewController *vc = [oldEditInfoViewController new];
        vc.text = _text;
        [self.navigationController pushViewController:vc animated:YES];
    }
}


@end
